import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: () => import('@/components/WrapMain'),
    redirect: '/main',
    children: [
      {
        path: 'main',
        name: 'main',
        redirect: '/main/discover/recommend',
        component: () => import('@/components/Main'),
        children: [
          {
            path: 'discover',
            component: () => import('@/components/content/DiscoverMusic'),
            children: [
              {
                path: 'recommend',
                name: 'recommend',
                component: () => import('@/components/content/Wrap')
              },
              {
                path: 'songList',
                name: 'songList',
                component: () => import('@/components/content/songList/SongList')
              },
              {
                path: 'topList',
                name: 'topList',
                component: () => import('@/components/content/songList/TopList')
              },
              {
                path: 'singer',
                name: 'singer',
                component: () => import('@/components/content/songList/Singer')
              },
              {
                path: 'lastestMusic',
                name: 'lastestMusic',
                component: () => import('@/components/content/songList/LastestMusic')
              },
              {
                path: 'mv',
                name: 'mv',
                component: () => import('@/components/content/Mv/Mv')
              },
              {
                path: 'videos',
                name: 'videos',
                component: () => import('@/components/content/Mv/Video')
              },
              {
                path: 'moveMv',
                name: 'moveMv',
                component: () => import('@/components/content/Mv/MoveMv')
              },
            ]
          },
          {
            path: 'search/:word',
            name: 'search',
            component: () => import('@/components/content/SearchResult')
          },
          {
            path: 'listDetail/:id',
            name: 'listDetail',
            component: () => import('@/components/content/SongListDetail')
          },
          {
            path: 'allMv',
            name: 'allMv',
            component: () => import('@/components/content/Mv/AllMv')
          }
        ]
      },
      {
        path: '/playPage/:id',
        name: 'playPage',
        component: () => import('@/components/PlayPage')
      }
    ]
  },
  {
    path: '/video/:id',
    name: 'video',
    component: () => import('@/components/Video')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
})

router.beforeEach((to, from, next) => {
  sessionStorage.setItem('prevPath', from.path);
  next();
})

export default router
